import http from "../index";

// 分页获取优惠券
export const getCoupons = ({
    ascended = null,
    current = null,
    size = null,
    sortFieldName = null,
    status = null,
    couponName = null,
    sendOut = null,
}) => {
    return http.get("coupons", {
        ascended,
        current,
        size,
        sortFieldName,
        status,
        couponName,
        sendOut,
    });
};

// 根据sid获取优惠券
export const getCouponDetail = ({ sid }) => {
    return http.get("coupons/" + sid);
};

// 新增优惠券
export const addCoupon = ({
    couponName,
    couponType,
    minAmount,
    preferential,
    limitation,
    expireTime = null,
    note = null,
    ratio = null,
    status = null,
    number = null,
}) => {
    return http.post("coupons", {
        couponName,
        couponType,
        minAmount,
        preferential,
        limitation,
        expireTime,
        note,
        ratio,
        status,
        number,
    });
};

// 修改优惠券
export const editCoupon = ({
    sid,
    couponName,
    couponType,
    minAmount,
    preferential,
    limitation,
    expireTime = null,
    note = null,
    ratio = null,
    status = null,
    number = null,
}) => {
    return http.put("coupons/" + sid, {
        couponName,
        couponType,
        minAmount,
        preferential,
        limitation,
        expireTime,
        note,
        ratio,
        status,
        number,
    });
};

// 批量删除优惠券
export const delCoupons = ({ sidList }) => {
    return http.put("coupons/delete", { sidList });
};

// 根据sid发放某优惠卷
export const grantCoupon = ({ sid }) => {
    return http.put("coupons/" + sid + "/grant");
};

// 根据sid启用-停用优惠券
export const changeCouponStatus = ({ sid }) => {
    return http.put("coupons/" + sid + "/status");
};
